<?php
declare(strict_types=1);
namespace cms\exam\admin\mvc_controller;

use cms\exam\service\AppService;
use cms\system\admin\mvc_controller\AbstractController;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpMessage\Exception\BadRequestHttpException;

class CommonController extends AbstractController
{
    /**
     * @Inject()
     * @var AppService
     */
    protected AppService $appService;

    /**
     * @param false $force
     * @param string $input
     * @return null
     */
    protected function _getApp(bool $force = false, string $input = 'app_id')
    {
        $app_id = (int) $this->request->input($input, 0);
        $app = $this->appService->getDataById($app_id);
        if ($force && !$app) {
            throw new BadRequestHttpException('参数错误');
        }
        return $app;
    }
}